# 封装发短信任务函数
from celery_tasks.main import celery_app
from celery_tasks.sms.yuntongxun.sms import CCP

# 发送短信模板ID
SMS_CODE_TEMP_ID = 1
import logging

logger = logging.getLogger('django')


@celery_app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code,expires):
    ccp = CCP()
    try:
        # 发送短信   手机号   验证码  时间  模版
        res = ccp.send_template_sms(mobile, [sms_code, expires], 1)
    except Exception as e:
        logger.error('发送异常: mobile:%s, sms_code: %s]' % (mobile, sms_code))
    else:

        if res != 0:
            logger.error('发送失败: mobile:%s, sms_code: %s]' % (mobile, sms_code))
        else:
            logging.info('发送成功: [mobile: %s] [sms_code: %s]' % (mobile, sms_code))


